package com.guizi.halftimesroom.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.guizi.halftimesroom.R;
import com.guizi.halftimesroom.bean.Rank;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;

/**
 * Created by Alan on 2016/7/20.
 */
public class TopRankView extends LinearLayout{
    private Context mContext;
    private ImageView iv_illusttop1,iv_illusttop2,iv_illusttop3,iv_illusttop4,iv_illusttop5;
    private CircleImageView cv_illustheadpic1,cv_illustheadpic2,cv_illustheadpic3,cv_illustheadpic4,cv_illustheadpic5;
    private TextView tv_illusttop1,tv_illusttop2,tv_illusttop3,tv_illusttop4,tv_illusttop5;
    private List<ImageView> iamges;
    private List<CircleImageView> circleImages;
    private List<TextView> tvList;

    public TopRankView(Context context) {
        this(context,null);
    }

    public TopRankView(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }

    public TopRankView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context);
    }

    private void initView(Context context) {
        this.mContext = context;
        iamges= new ArrayList<>();
        circleImages = new ArrayList<>();
        tvList = new ArrayList<>();

        View view = LayoutInflater.from(mContext).inflate(R.layout.illust_topview, this);
        iv_illusttop1 = (ImageView) view.findViewById(R.id.iv_illusttop1);
        iv_illusttop2 = (ImageView) view.findViewById(R.id.iv_illusttop2);
        iv_illusttop3 = (ImageView) view.findViewById(R.id.iv_illusttop3);
        iv_illusttop4 = (ImageView) view.findViewById(R.id.iv_illusttop4);
        iv_illusttop5 = (ImageView) view.findViewById(R.id.iv_illusttop5);
        iamges.add(iv_illusttop1);
        iamges.add(iv_illusttop2);
        iamges.add(iv_illusttop3);
        iamges.add(iv_illusttop4);
        iamges.add(iv_illusttop5);

        cv_illustheadpic1 = (CircleImageView) view.findViewById(R.id.cv_illustheadpic1);
        cv_illustheadpic2 = (CircleImageView) view.findViewById(R.id.cv_illustheadpic2);
        cv_illustheadpic3 = (CircleImageView) view.findViewById(R.id.cv_illustheadpic3);
        cv_illustheadpic4 = (CircleImageView) view.findViewById(R.id.cv_illustheadpic4);
        cv_illustheadpic5 = (CircleImageView) view.findViewById(R.id.cv_illustheadpic5);
        circleImages.add(cv_illustheadpic1);
        circleImages.add(cv_illustheadpic2);
        circleImages.add(cv_illustheadpic3);
        circleImages.add(cv_illustheadpic4);
        circleImages.add(cv_illustheadpic5);


        tv_illusttop1 = (TextView) view.findViewById(R.id.tv_illusttop1);
        tv_illusttop2 = (TextView) view.findViewById(R.id.tv_illusttop2);
        tv_illusttop3 = (TextView) view.findViewById(R.id.tv_illusttop3);
        tv_illusttop4 = (TextView) view.findViewById(R.id.tv_illusttop4);
        tv_illusttop5 = (TextView) view.findViewById(R.id.tv_illusttop5);
        tvList.add(tv_illusttop1);
        tvList.add(tv_illusttop2);
        tvList.add(tv_illusttop3);
        tvList.add(tv_illusttop4);
        tvList.add(tv_illusttop5);

    }

    public void setData(List<Rank.DataBean> list){
        for (int i = 0; i <list.size() ; i++) {
            Picasso.with(mContext).load(list.get(i).getPost().getCover()).into(iamges.get(i));
            Picasso.with(mContext).load(list.get(i).getPost().getAvatar()).into(circleImages.get(i));
            tvList.get(i).setText(list.get(i).getPost().getUname());
        }
    }
}
